<?php

namespace App\Http\Controllers\Cruise\Feishu;

use App\Http\Controllers\BaseController;
use App\Service\Cruise\Check\CruiseOrderService;
use App\Service\OpenShop\SiteLocation\AuthService;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class CruiseController extends BaseController
{

    /**
     * 常规任务去巡检
     * @param Request $request
     * @param $shopId
     * @return JsonResponse
     * @throws GuzzleException
     */
    public function addSameTaskByShopId(Request $request, $shopId): JsonResponse
    {
        $authInfo = AuthService::getRmsUserInfo($request);
        return $this->success(CruiseOrderService::addTask($shopId, $authInfo['userId']));
    }

    /**
     * 专项任务领取
     * @param Request $request
     * @param $id
     * @return JsonResponse
     */
    public function addSpecialTaskByShopId(Request $request, $id): JsonResponse
    {
        $authInfo = AuthService::getRmsUserInfo($request);
        CruiseOrderService::achieveSpecialTask($id, $authInfo);
        return $this->success();
    }

    /**
     * 工厂任务去巡检
     * @throws GuzzleException
     */
    public function addCompanyTaskBySelfCompany(Request $request): JsonResponse
    {
        $authInfo             = AuthService::getRmsUserInfo($request);
        $cruiseCheckCompanyId = $request->post('cruiseCheckCompanyId', 0);
        $taskId               = $request->post('taskId', 0);
        return $this->success(CruiseOrderService::addCompanyTask($cruiseCheckCompanyId, $taskId, $authInfo['userId']));
    }

}
